function deepPrintTable(t, indent, visited)
    visited = visited or {}
    if visited[t] then
        print(string.rep("  ", indent) .. tostring(t) .. " <cycle detected>")
        return
    end
    visited[t] = true

    indent = indent or 0
    local prefix = string.rep("  ", indent)
    for k, v in pairs(t) do
        if type(v) == "table" then
            print(prefix .. tostring(k) .. ":")
            deepPrintTable(v, indent + 1, visited)  -- 递归打印子表
        else
            print(prefix .. tostring(k) .. ": " .. tostring(v))
        end
    end
end

function printTableWithMetatableFull(t)
    -- 打印表本身
    print(t)
    deepPrintTable(t, 1)

    -- 打印元表
    local mt = getmetatable(t)
    if mt ~= nil then
        deepPrintTable(mt, 1)
    end
end

-------------------------------
-- print _G
print('>>>>>>>>>> BEGIN _G <<<<<<<<<<')
printTableWithMetatableFull(_G)
print('>>>>>>>>>> END _G <<<<<<<<<<')
